# R 语言数据帧
#创建data frame
emp.data <- data.frame(
  emp_id = c(1:5),
  emp_name = c("Rick","Dan","Michele","Ryan","Gary"),
  salary = c(623.3,611.0,515.2,729.0,843.25),
  start_time = as.Date(c("2012-01-01","2013-09-23","2014-11-15","2016-02-02","2015-07-04")),
  stringsAsFactors = FALSE
)
print( emp.data );

# 使用str( )函数获取数据结构
str( emp.data )

# 使用summary() 获取统计数据的摘要和性质
print( summary( emp.data ))

# 从数据帧中提取数据

result <- data.frame(emp.data$emp_name,emp.data$salary);
print( result );

# 数据帧进行切片操作
result <- emp.data[1:2,]
print( result )

# 提取第2和第4列 第3和第5行
result<- emp.data[c(3,5),c(2,4)]
print( result );

# 扩展数据帧
emp.data$dept <- c("Python","Java","R","C++","C#");
print( emp.data )

# 合并数据帧
emp.new_data <- data.frame(
  emp_id = c(6:8),
  emp_name = c("Rasmi","Pranab","Tusar"),
  salary = c(578.0,722.5,632.8),
  start_time = as.Date(c("2013-05-21","2013-08-03","2014-06-17")),
  dept  = c("Linux","Windows","IOS"),
  stringsAsFactors = FALSE
)
print( emp.new_data )
cat("merge data frame ","
    ")
emp.finaldata <- rbind( emp.data,emp.new_data );
print( emp.finaldata )